home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ldb.zip / CBDRDEM2.CPP < prev    next >
C/C++ Source or Header  |  1991-10-18  |  3KB  |  133 lines

  1.     // cbdrdem2.cpp
  2.     // Demo CBinder defaulting to C strings!
  3.     // Link with binder.obj, sbinder.obj, cbinder.obj
  4.     
  5.     #include <fstream.h>
  6.     #include <iomanip.h>
  7.     #include "cbinder.hpp"
  8.  
  9.     #define ID_CBDR_STRCMP  1
  10.  
  11.     #pragma argsused
  12.     void display1(char * D, voiD M, int * A)
  13.     {
  14.         int i = strlen((char *)D);
  15.  
  16.  
  17.         *A += i;
  18.         cout << "length: " << setw(3) << i
  19.             << "   accumulated length: "
  20.             << setw(3)
  21.             << *A << "   string: "
  22.             << D << "\n";
  23.  
  24.     }
  25.  
  26.     void display2(char * D, unsigned * M)
  27.     {
  28.         cout << "node: " << setw(3)
  29.             << ++*M
  30.             << "   contents: "
  31.             << D << "\n";
  32.     }
  33.  
  34.     main()
  35.     {
  36.         CBinder B;
  37.  
  38.         CBinder::registerClass();
  39.  
  40.         B.pushCLN("Now is the time");
  41.         B.insQCLN("for all programmers");
  42.         B.insQCLN("");  // empty string should Q and stream!        
  43.         B.atInsCLN(B.Nodes(),"to stop reinventing");
  44.         B.insQCLN("the linked list!");
  45.         B.insQCLN("");  // empty string should Q and stream!
  46.  
  47.         cout << "\n\nOverloaded ++ and typecast: "
  48.             << "operators \n\n";
  49.  
  50.         while (B++)
  51.             cout << (char *)(voiD)B << "\n";
  52.  
  53.         cout << "\n\nOverloaded [] subscript"
  54.             << " operator \n\n";
  55.  
  56.         for (unsigned i = 0; i < B.Nodes(); i++)
  57.             cout << (char *)B[i] << "\n";
  58.  
  59.         cout << "\n\npress enter to continue ...";
  60.         cin.get();
  61.  
  62.         i = 0;
  63.  
  64.         cout << "\n\nForEach iterator \n\n";
  65.  
  66.         B.forEach((BDRforEachBlocK)display1,0,&i);
  67.  
  68.         cout << "\n\npress enter to continue ...";
  69.         cin.get();
  70.  
  71.         B.setComparE((BDRcomparE)strcmp);
  72.         
  73.         B.link();
  74.  
  75.         RegisterFunction(ID_CBDR_STRCMP,
  76.             (GenericFnC)B.ComparE());
  77.  
  78.         ofstream oS("cbdrdem2.txt");
  79.         if (oS)  {
  80.             oS << (StreamablE) B;
  81.             B.restream();
  82.             oS.close();
  83.             ifstream iS("cbdrdem2.txt");
  84.             if (iS)  {
  85.                 StreamablE C;
  86.                 iS >> C;
  87.                 iS.close();
  88.                 RestreamRegistry();
  89.                 if (C)
  90.                 {
  91.                   cout << "\n\nStreamed and"
  92.                     << " reloaded CBinder \n\n";
  93.                   i = 0;
  94.                   ((CBindeR)C)->forEach(
  95.                       (BDRforEachBlocK)
  96.                         display2,&i,0);
  97.                   ((CBindeR)C)->sort();
  98.                   cout << "\n\nStreamed and"
  99.                     << " reloaded CBinder"
  100.                     << " sorted on reloaded"
  101.                     << " compare fnc! \n\n";
  102.                   i = 0;
  103.                   ((CBindeR)C)->forEach(
  104.                       (BDRforEachBlocK)
  105.                         display2,&i,0);
  106.                   delete (CBindeR) C;
  107.                 }
  108.                 else
  109.                   cout << "\n\nUnable to reload"
  110.                     << " CBinder \n\n";
  111.             }
  112.             else
  113.                 cout << "\n\nUnable to reopen"
  114.                   << " stream for input of"
  115.                   << " of CBinder \n\n";
  116.         }
  117.  
  118.         cout << "\n\npress enter to continue ...";
  119.         cin.get();
  120.  
  121.         cout << "\n\nCBinder streamed directly to"
  122.             << " cout \n\n";
  123.  
  124.         cout << (StreamablE) B;
  125.         B.restream();
  126.  
  127.  
  128.         cout << "\n\npress enter to quit ...";
  129.         cin.get();
  130.  
  131.         return 0;
  132.     }
  133.